﻿module lang.d.sts.dsyntaxelement;

import lang.isyntaxelement;
import lang.d.sts.declarations.ddeclaration;
public import lang.d.visitors.dvisitor;

abstract class DSyntaxElement: ISyntaxElement {
    private int myStartIndex;
    private int myEndIndex;
    private DSyntaxElement myParent;

    public void setStartIndex(in int index) {
        myStartIndex = index;
    }

    public int getStartIndex() const {
        return myStartIndex;
    }

    public void setEndIndex(in int index) {
        myEndIndex = index;
    }

    public int getEndIndex() const {
        return myEndIndex;
    }

    public void setParent(DSyntaxElement parent) {
        myParent = parent;
    }

    public DSyntaxElement getParent() {
        return myParent;
    }
    
    public DDeclaration getParentDeclaration() {
        return getParentByType!DDeclaration();
    }

    public T getParentByType(T: DSyntaxElement)() {
        if (myParent is null) {
            return null;
        }
        if ((cast(T) myParent) !is null) {
            return cast(T) myParent;
        }
        return myParent.getParentByType!T();
    }

    public void accept(DVisitor visitor);
}
